import { createWebHistory, createRouter } from 'vue-router'
import Layout from '@/layout'
import { TrendCharts } from '@element-plus/icons-vue'



/**
 * Note: 路由配置项
 *
 * hidden: true                     // 当设置 true 的时候该路由不会再侧边栏出现 如401，login等页面，或者如一些编辑页面/edit/1
 * alwaysShow: true                 // 当你一个路由下面的 children 声明的路由大于1个时，自动会变成嵌套的模式--如组件页面
 *                                  // 只有一个时，会将那个子路由当做根路由显示在侧边栏--如引导页面
 *                                  // 若你想不管路由下面的 children 声明的个数都显示你的根路由
 *                                  // 你可以设置 alwaysShow: true，这样它就会忽略之前定义的规则，一直显示根路由
 * redirect: noRedirect             // 当设置 noRedirect 的时候该路由在面包屑导航中不可被点击
 * name:'router-name'               // 设定路由的名字，一定要填写不然使用<keep-alive>时会出现各种问题
 * query: '{"id": 1, "name": "ry"}' // 访问路由的默认传递参数
 * meta : {
    noCache: true                   // 如果设置为true，则不会被 <keep-alive> 缓存(默认 false)
    title: 'title'                  // 设置该路由在侧边栏和面包屑中展示的名字
    icon: 'svg-name'                // 设置该路由的图标，对应路径src/assets/icons/svg
    breadcrumb: false               // 如果设置为false，则不会在breadcrumb面包屑中显示
    activeMenu: '/system/user'      // 当路由设置了该属性，则会高亮相对应的侧边栏。
  }
 */

// 公共路由
export const constantRoutes = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@/views/redirect/index.vue')
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login'),
    hidden: true
  },
  {
    path: '/sociallogin',
    component: () => import('@/views/socialLogin'),
    hidden: true
  },
  {
    path: '/register',
    component: () => import('@/views/register'),
    hidden: true
  },
  {
    path: '/:pathMatch(.*)*',
    component: () => import('@/views/error/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/error/401'),
    hidden: true
  },
  {
    path: '/error',
    component: () => import('@/views/error/Error'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/consumption',
    meta: {
      title: "能耗监测与分析",
      icon: "energy"
    },
    children: [
      {
        path: 'consumption',
        component: () => import('@/views/monitoring.vue'),
        name: 'monitoring',
        meta: {
          title: '实时监测'
        }
      },
      {
        path: 'analyse',
        component: () => import('@/views/analyse.vue'),
        name: 'analyse',
        meta: {
          title: '分析评估与优化建议'
        }
      }
    ]
  },
  {
    path: '/report',
    component: Layout,
    redirect: '/report/overview',
    meta: { title: '报表展示', icon: 'document' },
    children: [
      { path: 'overview', name: 'OverviewReport', component: () => import('@/views/report/OverviewReport.vue'), meta: { title: '总览报表' } },
      { path: 'region', name: 'RegionReport', component: () => import('@/views/report/RegionReport.vue'), meta: { title: '区域报表' } },
      { path: 'device', name: 'DeviceReport', component: () => import('@/views/report/DeviceReport.vue'), meta: { title: '设备报表' } }
    ]
  },
  {
    path: '/decision',
    component: Layout,
    redirect: '/decision/center',
    meta: {
      title: '智能决策与调度优化',
      icon: 'cpu' // 可自定义为 strategy.svg 或智能图标
    },
    children: [
      {
        path: 'center',
        name: 'DecisionCenter',
        component: () => import('@/views/decision/DecisionCenter.vue'),
        meta: { title: '智能建议中心' }
      },
      {
        path: 'plan',
        name: 'OptimizationPlan',
        component: () => import('@/views/decision/OptimizationPlan.vue'),
        meta: { title: '调度策略生成' }
      },
      {
        path: 'simulate',
        name: 'SimulationPanel',
        component: () => import('@/views/decision/SimulationPanel.vue'),
        meta: { title: '策略模拟分析' }
      },
      {
        path: 'monitor',
        name: 'ExecutionMonitor',
        component: () => import('@/views/decision/ExecutionMonitor.vue'),
        meta: { title: '策略执行监控' }
      }
    ]
  },
  {
    path: '/asset',
    component: Layout,
    redirect: '/asset/devices',
    meta: {
      title: '设备与资产管理',
      icon: 'monitor'  // 可替换为合适图标
    },
    children: [
      {
        path: 'devices',
        name: 'DeviceLedger',
        component: () => import('@/views/asset/DeviceLedger.vue'),
        meta: { title: '设备台账' }
      },
      {
        path: 'maintenance',
        name: 'MaintenanceLog',
        component: () => import('@/views/asset/MaintenanceLog.vue'),
        meta: { title: '维护记录' }
      }
    ]
  },
  {
    path: '/alarm',
    component: Layout,
    redirect: '/alarm/monitor',
    meta: {
      title: '预警管理',
      icon: 'warning'
    },
    children: [
      {
        path: 'rules',
        name: 'AlarmRules',
        component: () => import('@/views/alarm/Rule.vue'),
        meta: { title: '预警规则配置' }
      },
      {
        path: 'monitor',
        name: 'AlarmMonitor',
        component: () => import('@/views/alarm/AlarmMonitor.vue'),
        meta: { title: '实时预警' }
      }
    ]
  }




]

const router = createRouter({
  history: createWebHistory(import.meta.env.VITE_APP_ROUTER_PREFIX),
  routes: constantRoutes,
  scrollBehavior(to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition
    } else {
      return { top: 0 }
    }
  }
})

export default router
